import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/*This class will help in completing list of stop words*/
/*@Note: This program will only run for one time as all the stop words list 
 * have been created*/

/*1. Read intial set stop words
 *2. Clean Them
 *3. 
 * 
 * */


//
public class create_stop_words 
{
	
	Connection conn;
	
	String userName = "root";
	String password = "123";
	String database= "lsi";
	String table = "st_init";
	String Final_Word [];
	String final_stop_word_table  = "stop_words";
	
	
	void read_input()
	{  db_conn db = new db_conn();
	   preprocess prob  = new preprocess();
	 
	  Connection  conn  = db.initdb(database, table, userName, password);
		
		String str = "select * from  "+table;
		System.out.println(" Str = "+str);
		String all_words ="";
		
		try 
		{		
		 Statement stmt =  conn.createStatement();
		 stmt.execute(str);
		 ResultSet rs = stmt.getResultSet();
			
		 int count = 0;
		 while(rs.next())
		 {
			 all_words = all_words +rs.getString("word")+" ";
		 }
			
			
			System.out.println("count = "+count);
			 all_words  = all_words.trim();
			 all_words =prob.clean(all_words).trim();
			 all_words = prob.remove_SW_and_STEM(all_words);
			 all_words = all_words.trim();
			 
			Final_Word = all_words.split(" ");
			
		
			for(int i=0;i<Final_Word.length;i++)
			{
				try{	
				String insertStr ="Insert into "+ final_stop_word_table +" values ('"+ Final_Word[i]+"')";
				System.out.println("insertStr="+insertStr);
				System.out.println("Final Word = "+ Final_Word[i]);
				stmt.executeUpdate(insertStr);
				}catch(Exception e)
				{e.printStackTrace();}
					
				
			}
		
			 //if(stmt!=null)
				// stmt.close();
			if(conn!=null)
				conn.close();				
			
		}catch(SQLException e)
		{e.printStackTrace();}
		
	}
	
	public static void main(String args[])
	{
		
		create_stop_words csw =  new create_stop_words();
		System.out.println("Dont forget to input domain specific stop words from Excel File");
		
		BufferedReader br =  new BufferedReader(new InputStreamReader (System.in));
		try {
			br.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        csw.read_input();	
       
		
		
	}

}
